package com.lims;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class ExcelReader {
    public static void main(String[] args) throws IOException {
        FileInputStream file = new FileInputStream(new File("C:\\test.xlsx"));
        Workbook workbook = new XSSFWorkbook(file);
        int sheetNum =workbook.getNumberOfSheets();
        //读取sheet内容
        Sheet sheet2 = workbook.getSheetAt(0);
        Map<String,String> map = new TreeMap<>();
        checkUrl(sheet2,map);
        workbook.close();
    }

    private static void checkUrl(Sheet sheet,Map<String,String> map) {
        try {
            Iterator<Row> rowIterator = sheet.iterator();
            String sheetName = sheet.getSheetName();
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                Cell cell0 =  row.getCell(0);
                String cell0Msg = cell0 == null ? "" : cell0.getStringCellValue();
                map.put("cell0Msg",cell0Msg);
            }
            System.out.println(sheet.getSheetName() + "读取完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
